﻿using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {
	
	static public GameObject player;
	static public int playerScore;
	static public int playerSkillPoint = 100;
	
	public GameObject gridBase;
	
	public GameObject selectionObject;
	
	public GameObject bulletPrefab;
	public Texture[] bulletTextures;
	
	public Texture[] enemyShipTexture;
	
	public Texture[] enemyTexturePack1;
	public Texture[] enemyTexturePack2;
	public Texture[] enemyTexturePack3;
	
	static public int currentLevelIndex;
	static public byte[,] currentLevelGrid;
	static public GameObject[,] currentLevelObjects;
	
	static public GameObject currentBullet;
	static public int currentBulletColor;
	static public int tempBulletColor;
	
	public GameObject explosionNormal;
	public GameObject explosionSmallCombo;
	public GameObject explosionBigCombo;
	
	static public bool superBoom = false;
	//static public bool changeBulletColor;
	static public bool changeEnemyColor;
	
	static public bool isWin = false;
	
	// Use this for initialization
	void Start () {
		GameCore.InitData();
		GameCore.InitLevel(1);
		player = GameObject.FindGameObjectWithTag("Player");
		gridBase = GameObject.FindGameObjectWithTag("GridBase");
		GenerateRandomColor();
	}
	
	// Update is called once per frame
	void Update () {
		if(isWin) {
			//Application.LoadLevel("2");
		}
	}
	
	 public void GenerateRandomColor () {
		int color = Random.Range(1, 4);
		
		currentBulletColor = color;
		tempBulletColor = color;
		
		GenerateBullet();
	}
	
	public void GenerateBullet () {
		GameObject bulletMark = GameObject.FindGameObjectWithTag("BulletMark");
		GameObject bullet = Instantiate(bulletPrefab) as GameObject;
		currentBullet = bullet;
		bullet.transform.position = bulletMark.transform.position;
		
		//Bullet's color
		bullet.renderer.material.mainTexture = bulletTextures[currentBulletColor];
		bullet.transform.parent = player.transform;
	}
}
